# 导入使用到的库
from sqlalchemy import Column, String ,Integer,create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
# 创建父类:
Base = declarative_base()
# print(type(Base))
# 定义对象math:
class math(Base):
    # 对应表名math:
    __tablename__ = 'math'

    # 字段结构:
    id = Column(String(20), primary_key=True)
    name = Column(String(20))
    ms = Column(Integer)    

# 初始化数据库连接:
engine = create_engine('mysql+mysqlconnector://root:password@localhost:3306/score')
# 创建DBSession类型:
DBSession = sessionmaker(bind=engine)
# 创建Session:
session = DBSession()
# 创建Query查询，返回所有行:
user = session.query(math.id,math.name,math.ms).all()
# 输出类型、值:
print('type:', type(user))
for x in user:
    print(x)
# 关闭Session:
session.close()